const bcrypt = require('bcryptjs');

async function generatePassword() {
  const password = 'admin123';
  
  console.log('🔐 生成密码哈希');
  console.log('原始密码:', password);
  
  // 生成哈希
  const hash = await bcrypt.hash(password, 10);
  console.log('生成的哈希:', hash);
  
  // 验证哈希
  const isValid = await bcrypt.compare(password, hash);
  console.log('验证结果:', isValid);
  
  // 验证数据库中的哈希
  const dbHash = '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi';
  const isDbValid = await bcrypt.compare(password, dbHash);
  console.log('数据库哈希验证结果:', isDbValid);
  
  // 生成新的哈希用于更新数据库
  console.log('\n📝 更新数据库的SQL语句:');
  console.log(`UPDATE users SET password = '${hash}' WHERE username = 'admin';`);
  console.log(`UPDATE users SET password = '${hash}' WHERE username = 'test';`);
}

generatePassword();
